#ifndef _LevelBuilder_H_
#define _LevelBuilder_H_

#include "wiisprite.h"
#include <vector.h>
#include <string.h>

#include "common.h"
#include "Box2D.h"

#include "cake.h"

#include "mxml.h"

#include "soundmanager.h"

#include "storydata.h"

using namespace wsp;
using namespace Common;


class LevelBuilder {
	public:
		LevelBuilder(SoundManager* ptrSndManager);
		~LevelBuilder();

		bool Save(char* filename);
		bool LoadFromFile(char* filename);
		bool LoadFromBuffer(char* buffer);

		bool ParseTree(mxml_node_t *tree);

		bool Update();

		void Render(float dx, float dy, bool in_game = false);

		float GetStartX(){if(m_startSet) return m_startSprite.GetX();
						  else return 0;}

		float GetStartY(){if(m_startSet) return m_startSprite.GetY();
						  else return 0;}

		void Phyisicize(b2World* w);

		void ConstructCakes(std::vector<Cake*> *cakeVector);
		void ConstructNpZones(std::vector<Quad*> *npZones);
		
		void ConstructGround(std::vector<Sprite*> *ground);
		void ConstructTransGround(std::vector<Sprite*> *transGround);
		void ConstructStoryText(std::vector<StoryData*> *storyText);
		
		void Init();

		void CleanPhysics();

		int GetStoryTextSize(){return (int)_storyText.size();}

		bool UnsavedChanges(){return _unsavedChanges;}

	private:
		b2World* m_world;

		void ClearAll();
		void AddElement();
		void DeleteSelected();
		void ResizeQuad(Quad* q);
	  
		bool m_startSet;
		bool _unsavedChanges;
		
		std::vector<Image*> images;  

		Sprite m_drawSprite;

		Sprite m_startSprite;

		std::vector<Sprite*> m_cakeSprites;

		std::vector<Sprite*> m_groundSprites;
		std::vector<Sprite*> m_transGroundSprites;

		std::vector<Quad*> m_nonPortalWallSprites;

		std::vector<b2Body*> m_bodies;

		Builder::Type m_currentType;

		float m_screenOffsetX;
		float m_screenOffsetY;

		float m_downA_X;
		float m_downA_Y;

		bool m_isDrawing;
		bool m_isRunning;

		std::vector<StoryData*> _storyText;

		SoundManager* _ptrSndManager;

                int _saveIndex;

};

#endif //_LevelBuilder_H_
